package com.jy.api.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by lihu on 2018/3/24.
 */
@Service
public class ClerkSaleDaoImpl implements ClerkSaleDao {


    @Autowired
    JdbcTemplate jdbcTemplate;


    public Double queryMonthTotal(String employeeId, String storeId, int month) {

        String sql = " select ifnull(sum(b.amount),0)" +
                " from d_date a left join f_daily_employee_kpi b on(a.day=b.bizdate)" +
                "where a.month=? and b.store_id=? and  b.employee_id=?";
        return jdbcTemplate.queryForObject(sql, Double.class, month, storeId, employeeId);
    }


    public List<Map<String, Object>> queryTypeCount(String employeeId, String storeId, int month) {
        String sql = " select b.product_type_id productTypeId, sum(b.amount) amount,sum(b.quantity) quantity " +
                " from d_date a left join f_daily_employee_kpi b on(a.day=b.bizdate)" +
                "where a.month=? and  b.store_id=? and  b.employee_id=? group by productTypeId";
        return jdbcTemplate.queryForList(sql, month, storeId, employeeId);
    }
}
